#ifndef XYMODEM_H
#define XYMODEM_H

#include "icom.h"
#include "xymodemfile.h"

class Xymodem
{
public:
    Xymodem();
	Xymodem(ICom *com);
    ~Xymodem();

	void SetComInterface(ICom *com);
	void SetType(QString type);
	void SetFile(const QString &file_path);

    int start() const;

    int stop() const;

    enum modem_t {
		NONE = 0x00,
        SOH = 0x01,
        STX = 0x02,
        EOT = 0x04,
        ACK = 0x06,
        NAK = 0x15,
        CAN = 0x18,
        CHC = 0x43,
        TIMEOUT = 0xFF
    };

    enum modem_type_t {
        xmodem,
        ymodem,
        zmodem
    };

private:
    ICom *m_com{};

	XymodemFile *m_file{};
    int m_type{};

    modem_t get(ComMessage &msg) const;
	modem_t post(ComMessage &msg, QByteArray body) const;
	void put(ComMessage &msg, QByteArray body) const;
    QByteArray make_head_packet() const;
	QByteArray make_body_packet(int block) const;
	QByteArray make_eot_packet() const;
	QByteArray make_cancel_packet() const;
	QByteArray make_null_paclet() const;
};

#endif // XYMODEM_H
